﻿namespace MvcFckEditor.Components
{
    using System;
    using System.Collections;
    using System.IO;
    using System.Text.RegularExpressions;

    internal sealed class Util
    {
        private Util()
        {
        }

        public static bool ArrayContains(Array array, object value, IComparer comparer)
        {
            foreach (object obj2 in array)
            {
                if (comparer.Compare(obj2, value) == 0)
                {
                    return true;
                }
            }
            return false;
        }

        public static string ArrayToSrting(string[] arr)
        {
            string str = string.Empty;
            foreach (string str2 in arr)
            {
                str = str + "," + str2;
            }
            if (str != string.Empty)
            {
                str = str.Substring(1);
            }
            return str;
        }

        public static DirectoryInfo CreateDirectory(string path)
        {
            DirectoryInfo info = new DirectoryInfo(Path.GetFullPath(path));
            try
            {
                if (!info.Exists)
                {
                    info.Create();
                }
                return info;
            }
            catch
            {
                return new DirectoryInfo(path);
            }
        }

        public static string SanitizeFileName(string fileName)
        {
            return Regex.Replace(fileName, "[\\\\/|:?*\"<>\\p{C}]", "_", RegexOptions.None);
        }

        public static string SanitizeFolderName(string folderName)
        {
            return Regex.Replace(folderName, "[.\\\\/|:?*\"<>\\p{C}]", "_", RegexOptions.None);
        }
    }
}

